<?php

namespace app\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Mdsparts;

/**
 * MdspartsSearch represents the model behind the search form about `app\models\Mdsparts`.
 */
class MdspartsSearch extends Mdsparts
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['id', 'universal_part', 'brand_id'], 'integer'],
            [['title', 'part_number', 'manufacturer_number', 'list_price', 'brand_title', 'description', 'fits', 'specifications_json', 'Quantity_Sold', 'Product_Fit', 'Warranty', 'Color_Finish', 'Material', 'Location', 'Series', 'Notes', 'Seat_Type', 'Fit_Note', 'Design', 'Position', 'Type', 'Row', 'Recommended_Use', 'Vehicle_Body_Type', 'Construction', 'Kit_Type'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Mdsparts::find();

        // add conditions that should always apply here

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        // grid filtering conditions
        $query->andFilterWhere([
            'id' => $this->id,
            'universal_part' => $this->universal_part,
            'brand_id' => $this->brand_id,
        ]);

        $query->andFilterWhere(['like', 'title', $this->title])
            ->andFilterWhere(['like', 'part_number', $this->part_number])
            ->andFilterWhere(['like', 'manufacturer_number', $this->manufacturer_number])
            ->andFilterWhere(['like', 'list_price', $this->list_price])
            ->andFilterWhere(['like', 'brand_title', $this->brand_title])
            ->andFilterWhere(['like', 'description', $this->description])
            ->andFilterWhere(['like', 'fits', $this->fits])
            ->andFilterWhere(['like', 'specifications_json', $this->specifications_json])
            ->andFilterWhere(['like', 'Quantity_Sold', $this->Quantity_Sold])
            ->andFilterWhere(['like', 'Product_Fit', $this->Product_Fit])
            ->andFilterWhere(['like', 'Warranty', $this->Warranty])
            ->andFilterWhere(['like', 'Color_Finish', $this->Color_Finish])
            ->andFilterWhere(['like', 'Material', $this->Material])
            ->andFilterWhere(['like', 'Location', $this->Location])
            ->andFilterWhere(['like', 'Series', $this->Series])
            ->andFilterWhere(['like', 'Notes', $this->Notes])
            ->andFilterWhere(['like', 'Seat_Type', $this->Seat_Type])
            ->andFilterWhere(['like', 'Fit_Note', $this->Fit_Note])
            ->andFilterWhere(['like', 'Design', $this->Design])
            ->andFilterWhere(['like', 'Position', $this->Position])
            ->andFilterWhere(['like', 'Type', $this->Type])
            ->andFilterWhere(['like', 'Row', $this->Row])
            ->andFilterWhere(['like', 'Recommended_Use', $this->Recommended_Use])
            ->andFilterWhere(['like', 'Vehicle_Body_Type', $this->Vehicle_Body_Type])
            ->andFilterWhere(['like', 'Construction', $this->Construction])
            ->andFilterWhere(['like', 'Kit_Type', $this->Kit_Type]);

        return $dataProvider;
    }
}
